package com.qf.controller;

import com.qf.dto.R;
import com.qf.pojo.Categories;
import com.qf.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    private CategoryService categoryService;
    @Autowired
    public void setCategoryService(CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    @GetMapping("/categories")
    public R findAllCategories(){
        List<Categories> categories = categoryService.findAllCategory();
        return R.setOk(categories);
    }

    @PostMapping("/newcategory/{categoryName}")
    public R newcategory(@PathVariable String categoryName ){

        categoryService.addcategory(categoryName);
        return R.setOk(null);
    }
}
